/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.accountBindInLogin.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.qihoo.gamecenter.sdk.common.view.CustButton;
import com.qihoo.gamecenter.sdk.common.view.CustEditText;
import com.qihoo.gamecenter.sdk.login.plugin.a.j;
import com.qihoo.gamecenter.sdk.login.plugin.a.k;
import com.qihoo.gamecenter.sdk.login.plugin.d.a;
import com.qihoo.gamecenter.sdk.login.plugin.h.e;
import com.qihoo.gamecenter.sdk.login.plugin.h.f;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

public class VerifyPhoneNumberDialog extends RelativeLayout {
    private com.qihoo.gamecenter.sdk.login.plugin.f.a a;
    private Activity b;
    private String c;
    private Intent d;
    private b e;
    private RelativeLayout f;
    private VerifyProgress g;
    private CustEditText h;
    private View i;
    private CustButton j;
    private String k;
    private String l;
    private String m;
    private ImageView n;
    private String o;
    private boolean p = false;
    private ImageView q;
    private View.OnClickListener r = new View.OnClickListener() {
        public void onClick(View paramView) {
            if (VerifyPhoneNumberDialog.g(VerifyPhoneNumberDialog.this) != paramView)
                return;
            VerifyPhoneNumberDialog.c(VerifyPhoneNumberDialog.this);
        }
    };

    public VerifyPhoneNumberDialog(Activity paramActivity, String paramString, Intent paramIntent, b paramb) {
        super(paramActivity);
        this.b = paramActivity;
        this.c = paramString;
        this.d = paramIntent;
        this.e = paramb;
        this.a = com.qihoo.gamecenter.sdk.login.plugin.f.a.a(this.b);
        c();
    }

    public void setVerifyProgress(VerifyProgress paramVerifyProgress) {
        this.g = paramVerifyProgress;
    }

    public void a(Map paramMap) {
        setVisibility(0);
        this.h.requestFocus();
    }

    private void c() {
        setBackgroundDrawable(this.a.a(-1073741797));
        setLayoutParams(new RelativeLayout.LayoutParams(f.a(this.b, 320.0F), -2));
        setGravity(17);
        a(this.b);
    }

    private void a(Context paramContext) {
        int i1 = f.a(paramContext, 16.0F);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -2);
        localLayoutParams.leftMargin = i1;
        localLayoutParams.rightMargin = i1;
        localLayoutParams.topMargin = i1;
        localLayoutParams.bottomMargin = i1;
        this.f = new RelativeLayout(paramContext);
        this.f.setLayoutParams(localLayoutParams);
        addView(this.f);
        this.f.addView(c(paramContext));
        this.f.addView(d(paramContext));
        this.f.addView(e(paramContext));
        this.f.addView(f(paramContext));
        addView(b(paramContext));
    }

    private View b(Context paramContext) {
        int i1 = f.a(paramContext, 10.0F);
        int i2 = f.a(paramContext, 10.0F);
        int i3 = f.a(paramContext, 19.0F);
        int i4 = f.a(paramContext, 12.0F);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(f.a(this.b, 32.0F), f.a(this.b,
                43.0F));
        localLayoutParams.topMargin = 0;
        localLayoutParams.rightMargin = 0;
        this.q = new ImageView(paramContext);
        localLayoutParams.addRule(10, -1);
        localLayoutParams.addRule(11, -1);
        this.q.setLayoutParams(localLayoutParams);
        this.q.setPadding(i1, i3, i2, i4);
        this.q.setScaleType(ImageView.ScaleType.FIT_XY);
        this.a.a(this.q, 1073741833, 1073741834, 1073741834);
        this.q.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramView) {
                f.a(VerifyPhoneNumberDialog.a(VerifyPhoneNumberDialog.this));
                com.qihoo.gamecenter.sdk.common.c localc = (com.qihoo.gamecenter.sdk.common.c) VerifyPhoneNumberDialog
                        .a(VerifyPhoneNumberDialog.this);
                localc.execCallback(null);
                VerifyPhoneNumberDialog.a(VerifyPhoneNumberDialog.this).finish();
                com.qihoo.gamecenter.sdk.login.plugin.accountBindInLogin.a.a.a(
                        VerifyPhoneNumberDialog.a(VerifyPhoneNumberDialog.this), true);
            }
        });
        return this.q;
    }

    private TextView c(Context paramContext) {
        TextView localTextView = new TextView(paramContext);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-2, -2);
        localLayoutParams.addRule(14, -1);
        localLayoutParams.topMargin = f.a(paramContext, 8.0F);
        localTextView.setLayoutParams(localLayoutParams);
        localTextView.setId(a.c.ordinal());
        localTextView.setGravity(17);
        localTextView.setTextColor(Color.parseColor("#ff7f16"));
        localTextView.setTextSize(1, com.qihoo.gamecenter.sdk.login.plugin.h.c.g);
        localTextView.getPaint().setFakeBoldText(true);
        localTextView.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.dO));
        return localTextView;
    }

    private TextView d(Context paramContext) {
        TextView localTextView = new TextView(paramContext);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -2);
        localLayoutParams.topMargin = f.a(paramContext, 18.0F);
        localLayoutParams.bottomMargin = f.a(paramContext, 18.0F);
        localLayoutParams.addRule(3, a.c.ordinal());
        localTextView.setLayoutParams(localLayoutParams);
        localTextView.setId(a.d.ordinal());
        localTextView.setGravity(16);
        String str = this.d.getStringExtra("bind_message");
        localTextView.setTextSize(1, com.qihoo.gamecenter.sdk.login.plugin.h.c.g);
        if (TextUtils.isEmpty(str))
            localTextView.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bg));
        else
            localTextView.setText(str);
        localTextView.setTextColor(-16777216);
        return localTextView;
    }

    private LinearLayout e(Context paramContext) {
        this.k = f.e(this.b);
        this.m = this.k;
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, f.a(paramContext, 47.0F));
        localLayoutParams.addRule(3, a.d.ordinal());
        LinearLayout localLinearLayout1 = new LinearLayout(paramContext);
        localLinearLayout1.setLayoutParams(localLayoutParams);
        localLinearLayout1.setId(a.e.ordinal());
        localLinearLayout1.setGravity(16);
        localLinearLayout1.setOrientation(0);
        LinearLayout.LayoutParams localLayoutParams1 = new LinearLayout.LayoutParams(-1, -1);
        localLayoutParams1.weight = 1.0F;
        LinearLayout localLinearLayout2 = new LinearLayout(paramContext);
        localLinearLayout2.setLayoutParams(localLayoutParams1);
        LinearLayout.LayoutParams localLayoutParams2 = new LinearLayout.LayoutParams(0, -2);
        localLayoutParams2.weight = 1.0F;
        LinearLayout.LayoutParams localLayoutParams3 = new LinearLayout.LayoutParams(-2, -2);
        localLinearLayout2.setOrientation(0);
        this.a.a(localLinearLayout2, -1073741801);
        localLinearLayout2.setPadding(f.a(paramContext, 6.0F), 0, 0, 0);
        localLinearLayout2.setGravity(16);
        TextView localTextView = new TextView(paramContext);
        localTextView.setTextColor(-16777216);
        localTextView.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bf));
        localTextView.setTextSize(1, com.qihoo.gamecenter.sdk.login.plugin.h.c.g);
        localLinearLayout2.addView(localTextView, localLayoutParams3);
        this.h = new CustEditText(paramContext);
        this.h.setText(this.k);
        this.h.setTextColor(-16777216);
        this.h.setSingleLine(true);
        this.h.setTextSize(1, com.qihoo.gamecenter.sdk.login.plugin.h.c.g);
        this.h.setHint(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bh));
        InputFilter[] arrayOfInputFilter = new InputFilter[1];
        arrayOfInputFilter[0] = new InputFilter.LengthFilter(11);
        this.h.setFilters(arrayOfInputFilter);
        this.h.setBackgroundColor(0);
        this.h.setInputType(2);
        this.h.setPadding(0, 0, 0, 0);
        this.h.setImeOptions(6);
        this.h.e();
        this.h.f();
        this.h.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            public boolean onEditorAction(TextView paramTextView, int paramInt, KeyEvent paramKeyEvent) {
                if ((((paramInt == 6) || (paramInt == 0)))
                        && (!(TextUtils.isEmpty(VerifyPhoneNumberDialog.b(VerifyPhoneNumberDialog.this).getText()
                                .toString()))))
                    VerifyPhoneNumberDialog.c(VerifyPhoneNumberDialog.this);
                return false;
            }
        });
        this.h.c();
        this.h.d();
        this.h.setOnFocusChangeListener(new View.OnFocusChangeListener(paramContext) {
            public void onFocusChange(View paramView, boolean paramBoolean) {
                if (!(paramBoolean))
                    return;
                VerifyPhoneNumberDialog.a(VerifyPhoneNumberDialog.this).getWindow().setSoftInputMode(4);
                InputMethodManager localInputMethodManager = (InputMethodManager) this.a
                        .getSystemService("input_method");
                if (TextUtils.isEmpty(VerifyPhoneNumberDialog.d(VerifyPhoneNumberDialog.this))) {
                    VerifyPhoneNumberDialog.b(VerifyPhoneNumberDialog.this).setSelection(0);
                    VerifyPhoneNumberDialog.e(VerifyPhoneNumberDialog.this).setVisibility(8);
                }
                else {
                    VerifyPhoneNumberDialog.b(VerifyPhoneNumberDialog.this).setSelection(
                            VerifyPhoneNumberDialog.d(VerifyPhoneNumberDialog.this).length());
                    VerifyPhoneNumberDialog.e(VerifyPhoneNumberDialog.this).setVisibility(0);
                }
                if (localInputMethodManager == null)
                    return;
                localInputMethodManager.showSoftInput(VerifyPhoneNumberDialog.b(VerifyPhoneNumberDialog.this), 1);
            }
        });
        this.n = new ImageView(paramContext);
        this.a.a(this.n, 1073741835);
        this.n.setVisibility(8);
        this.n.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramView) {
                VerifyPhoneNumberDialog.f(VerifyPhoneNumberDialog.this);
                VerifyPhoneNumberDialog.b(VerifyPhoneNumberDialog.this).setText("");
            }
        });
        this.h.a();
        this.h.b();
        this.h.addTextChangedListener(new TextWatcher() {
            public void onTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3) {
                if (!(TextUtils.isEmpty(paramCharSequence)))
                    VerifyPhoneNumberDialog.e(VerifyPhoneNumberDialog.this).setVisibility(0);
                else
                    VerifyPhoneNumberDialog.e(VerifyPhoneNumberDialog.this).setVisibility(8);
            }

            public void beforeTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3) {}

            public void afterTextChanged(Editable paramEditable) {
                if (TextUtils.isEmpty(paramEditable))
                    return;
                VerifyPhoneNumberDialog.f(VerifyPhoneNumberDialog.this);
            }
        });
        int i1 = f.a(paramContext, 8.0F);
        localLinearLayout2.addView(this.h, localLayoutParams2);
        localLinearLayout2.addView(this.n,
                new LinearLayout.LayoutParams(f.a(paramContext, 34.0F), f.a(paramContext, 34.0F)));
        this.n.setPadding(i1, i1, i1, i1);
        localLinearLayout1.addView(localLinearLayout2);
        return localLinearLayout1;
    }

    private LinearLayout f(Context paramContext) {
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -2);
        localLayoutParams.addRule(3, a.e.ordinal());
        localLayoutParams.topMargin = f.a(paramContext, 16.0F);
        LinearLayout localLinearLayout = new LinearLayout(paramContext);
        localLinearLayout.setLayoutParams(localLayoutParams);
        localLinearLayout.setOrientation(0);
        localLinearLayout.setGravity(17);
        localLinearLayout.setId(a.f.ordinal());
        this.j = new CustButton(paramContext);
        this.j.setLayoutParams(new LinearLayout.LayoutParams(-1, f.a(this.b, 47.0F)));
        this.j.setGravity(17);
        this.j.setTextColor(-1);
        this.j.setTextSize(1, com.qihoo.gamecenter.sdk.login.plugin.h.c.l);
        this.j.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bi));
        this.j.a();
        this.j.b();
        this.j.setOnClickListener(this.r);
        this.a.a(this.j, -1073741764, -1073741763, -1073741763);
        localLinearLayout.addView(this.j);
        return localLinearLayout;
    }

    private void a(String paramString) {
        if (this.i != null) {
            localObject = (TextView) this.i.findViewById(10001);
            ((TextView) localObject).setText(paramString);
            return;
        }
        Object localObject = new RelativeLayout(this.b);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-2, -2);
        localLayoutParams.addRule(2, a.e.ordinal());
        this.f.addView((View) localObject, localLayoutParams);
        TextView localTextView = new TextView(this.b);
        localTextView.setId(10001);
        localTextView.setText(paramString);
        localTextView.setTextColor(Color.parseColor("#e46052"));
        this.a.a(localTextView, -1073741766);
        localTextView.setPadding(4, 0, 4, 0);
        localTextView.setTextSize(1, com.qihoo.gamecenter.sdk.login.plugin.h.c.i);
        ((RelativeLayout) localObject).addView(localTextView, new RelativeLayout.LayoutParams(-2, -2));
        localTextView.setVisibility(4);
        localTextView.post(new Runnable(localTextView) {
            public void run() {
                this.a.setVisibility(0);
            }
        });
        this.i = ((View) localObject);
    }

    private void d() {
        if (this.i == null)
            return;
        this.f.removeView(this.i);
        this.i = null;
    }

    public void a() {
        setVisibility(8);
        if (this.g == null)
            return;
        this.g.a();
    }

    private void e() {
        d();
        this.k = this.h.getText().toString();
        e.a("VerifyPhoneNumberDialog", new Object[] { "phone number is " + this.k });
        e.a("VerifyPhoneNumberDialog", new Object[] { "local phone number is " + this.m });
        com.qihoo.gamecenter.sdk.login.plugin.accountBindInLogin.a.a.a(this.b, false);
        if (!(f.a(this.b, com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.c), this.c)))
            return;
        if (TextUtils.isEmpty(this.k)) {
            a(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bz));
            return;
        }
        if (!(f.c(this.k))) {
            a(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bB));
            return;
        }
        if (this.k.length() != 11) {
            a(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bC));
            return;
        }
        if (!(f.d(this.k))) {
            a(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bB));
            return;
        }
        if (!(this.k.equals(this.l))) {
            this.e.a(3, -1, null);
        }
        else {
            HashMap localHashMap = new HashMap();
            localHashMap.put("localPhoneNumber", this.m);
            localHashMap.put("phoneNumber", this.k);
            this.e.a(4, -1, localHashMap);
        }
    }

    public void b() {
        f.a(this.b);
        this.g.a(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bj));
        k localk = new k(getContext(), this.c);
        localk.a(this.k, this.k.equals(this.m), false, new j() {
            public void a(String paramString) {
                VerifyPhoneNumberDialog.a(VerifyPhoneNumberDialog.this, "");
                String str1 = com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bF);
                if (!(TextUtils.isEmpty(paramString)))
                    try {
                        e.a("VerifyPhoneNumberDialog", new Object[] { "onSmsCodeFetched result  is " + paramString });
                        JSONObject localJSONObject = new JSONObject(paramString);
                        int i = localJSONObject.getInt("errno");
                        if (0 == i) {
                            VerifyPhoneNumberDialog.a(VerifyPhoneNumberDialog.this,
                                    VerifyPhoneNumberDialog.d(VerifyPhoneNumberDialog.this));
                            String str2 = localJSONObject.optString("smscode", "");
                            if (TextUtils.isEmpty(str2)) {
                                VerifyPhoneNumberDialog.h(VerifyPhoneNumberDialog.this);
                            }
                            else {
                                VerifyPhoneNumberDialog.b(VerifyPhoneNumberDialog.this, str2);
                                VerifyPhoneNumberDialog.i(VerifyPhoneNumberDialog.this);
                            }
                        }
                        else if (!(VerifyPhoneNumberDialog.j(VerifyPhoneNumberDialog.this))) {
                            str1 = localJSONObject.getString("errmsg");
                            VerifyPhoneNumberDialog.c(VerifyPhoneNumberDialog.this, str1);
                        }
                        else {
                            VerifyPhoneNumberDialog.h(VerifyPhoneNumberDialog.this);
                        }
                    } catch (Exception localException) {
                        e.b("VerifyPhoneNumberDialog", localException.getLocalizedMessage());
                        VerifyPhoneNumberDialog.c(VerifyPhoneNumberDialog.this, str1);
                    }
                else
                    VerifyPhoneNumberDialog.c(VerifyPhoneNumberDialog.this, str1);
            }
        });
    }

    private void f() {
        new AsyncTask() {
            protected String a(Void[] paramArrayOfVoid) {
                String str1 = com.qihoo.gamecenter.sdk.login.plugin.accountBindInLogin.a.a.a(VerifyPhoneNumberDialog
                        .a(VerifyPhoneNumberDialog.this), VerifyPhoneNumberDialog.d(VerifyPhoneNumberDialog.this),
                        VerifyPhoneNumberDialog.k(VerifyPhoneNumberDialog.this),
                        com.qihoo.gamecenter.sdk.login.plugin.h.d.d(), com.qihoo.gamecenter.sdk.login.plugin.h.a
                                .a(VerifyPhoneNumberDialog.l(VerifyPhoneNumberDialog.this)));
                String str2 = com.qihoo.gamecenter.sdk.login.plugin.d.a.a(
                        VerifyPhoneNumberDialog.a(VerifyPhoneNumberDialog.this), str1);
                return str2;
            }

            protected void a(String paramString) {
                e.a("VerifyPhoneNumberDialog", new Object[] { "verifySMSCode is" + paramString });
                if (!(TextUtils.isEmpty(paramString)))
                    try {
                        JSONObject localJSONObject = new JSONObject(paramString);
                        int i = localJSONObject.getInt("errno");
                        e.a("VerifyPhoneNumberDialog", new Object[] { "err  is " + i });
                        if (i == 0)
                            VerifyPhoneNumberDialog.m(VerifyPhoneNumberDialog.this);
                        else
                            VerifyPhoneNumberDialog.h(VerifyPhoneNumberDialog.this);
                    } catch (JSONException localJSONException) {
                        e.b("VerifyPhoneNumberDialog", localJSONException.getLocalizedMessage());
                        VerifyPhoneNumberDialog.h(VerifyPhoneNumberDialog.this);
                    }
                else
                    VerifyPhoneNumberDialog.h(VerifyPhoneNumberDialog.this);
            }
        }.execute(new Void[0]);
    }

    private void g() {
        HashMap localHashMap = new HashMap();
        localHashMap.put("localPhoneNumber", this.m);
        localHashMap.put("phoneNumber", this.k);
        this.e.a(4, -1, localHashMap);
        this.g.a();
    }

    private void b(String paramString) {
        this.e.a(2, -1, null);
        this.g.a();
        a(paramString);
    }

    private void h() {
        this.g.b(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.bx));
        this.g.postDelayed(new Runnable() {
            public void run() {
                VerifyPhoneNumberDialog.n(VerifyPhoneNumberDialog.this).a();
                HashMap localHashMap = new HashMap();
                localHashMap.put("phoneNumber", VerifyPhoneNumberDialog.d(VerifyPhoneNumberDialog.this));
                VerifyPhoneNumberDialog.o(VerifyPhoneNumberDialog.this).a(6, 1, localHashMap);
            }
        }, 1000L);
    }
}